package com.ryskoo.framework.core.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Sha1Util {
	
	
	public static String getsha1(String str) {
		if(str == null){
		  return null;
		}else {
			try {
			    MessageDigest messageDigest = MessageDigest.getInstance("SHA1");   
				messageDigest.update(str.getBytes());
				return getFormattedText(messageDigest.digest());
			} catch (NoSuchAlgorithmException e) {
				e.printStackTrace();
			}
		
		}
		return null;
	}
	 
    private static String getFormattedText(byte[] bytes) {
        String des = "";
        String tmp = null;
        for (int i=0; i< bytes.length; i++) {
           tmp = (Integer.toHexString(bytes[i] & 0xFF));
           if (tmp.length() == 1) {
               des += "0";
           }
           des += tmp;
        }
       return des;
    }
}
